//
//  FyClassTitleView.m
//  B2C
//
//  Created by 冯琰琰 on 5/8/2018.
//  Copyright © 2018 lixiaolong. All rights reserved.
//

#import "FyClassTitleView.h"
#import "UIButton+EdgeInsetsStyleBtn.h"

@interface FyClassTitleView()

@property (nonatomic, strong) NSArray *BtnInfoArray;

@end


@implementation FyClassTitleView

-(instancetype)initWithFrame:(CGRect)frame btnInfoArray:(NSArray *)btnInfoArray{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _BtnInfoArray = btnInfoArray;
        [self setSubViews];
    }
    return self;
}

-(void)setSubViews{
    UIImageView *lineView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"line_category"]];
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self);
        make.height.equalTo(@2);
    }];
    
    CGFloat width_Btn = (ScreenWidth / 3 - 2) ;
    for (int i = 0; i < 3; i++) {
        NSDictionary *btnInfo = _BtnInfoArray[i];
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:btnInfo[@"title"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:btnInfo[@"image"]] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithHex:0x333333 alpha:1] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithHex:0x7abe45 alpha:1] forState:UIControlStateSelected];
        [self addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset( i * width_Btn + i);
            make.top.bottom.equalTo(self);
            make.width.mas_equalTo(width_Btn);
        }];
        if (i > 0) {
            [btn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:10];
        }
        
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        
        if (i < 2) {
            UIView *lineView = [[UIView alloc]init];
            lineView.backgroundColor = [UIColor colorWithHex:0xcccccc alpha:1];
            [self addSubview:lineView];
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(1);
                make.left.equalTo(btn.mas_right);
                make.height.mas_equalTo(13);
                make.centerY.equalTo(btn);
            }];
        }
    }
    
}
@end
